<%	
    # Create the helper
  	flex_scaffold_helper = FlexScaffoldHelper.new("#{actions.first.camelcase}")

-%>package <%= class_name.downcase.gsub('::','.') %>.business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	
	import org.genuflex.utils.GenuflexDataFunctions;
	
	import <%= class_name.downcase.gsub('::','.') %>.vo.<%= actions.first.camelcase %>VO;
	
	public class <%= actions.first.camelcase %>Delegate extends <%= file_name.camelcase %>Delegate
	{
		
		public function <%= actions.first.camelcase %>Delegate(responder : IResponder)
		{
			InitializeRemoteObject(responder, "<%= actions.first.camelcase %>Service");
		}
		
		// Use a remote object interface to pull back a single <%= actions.first %> object
		public function find<%= actions.first.camelcase %>ById(id : int) : void
		{
		      var call : AsyncToken = remoteObjectService.find_by_id(id);
		      call.addResponder( responder );			
		}		
				
		// Use a remote object interface to pull back all <%= actions.first %> objects 
		public function findAll<%= actions.first.pluralize.camelcase %>() : void
		{
		      var call : AsyncToken = remoteObjectService.find_all();
		      call.addResponder( responder );			
		}		

		// Use a remote object interface to save one <%= actions.first %> object
		public function save<%= actions.first.camelcase %>(<%= flex_scaffold_helper.obj_name %> : <%= actions.first.camelcase %>VO) : void
		{
			if (<%= flex_scaffold_helper.obj_name %> != null) {
<%	flex_scaffold_helper.habtm_associations.each do | assoc | 

%><%= "\t\t\t\t" + flex_scaffold_helper.obj_name %>.<%=assoc.klass().to_s.underscore.downcase %>_ids = GenuflexDataFunctions.buildIDList(<%= flex_scaffold_helper.obj_name %>.<%=assoc.name%>);
<%
	end #has_many_associations + habtm_associations.each
%>				
		    	var call : AsyncToken = remoteObjectService.save(<%= flex_scaffold_helper.obj_name %>);
		    	call.addResponder( responder );			
		 	}
		}	

		// Use a remote object interface to destroy one <%= actions.first %> object
		public function destroy<%= actions.first.camelcase %>(<%= flex_scaffold_helper.obj_name %> : <%= actions.first.camelcase %>VO) : void
		{
			if (<%= flex_scaffold_helper.obj_name %> != null) {
		    	var call : AsyncToken = remoteObjectService.destroy(<%= flex_scaffold_helper.obj_name %>.id);
		    	call.addResponder( responder );			
		 	}
		}
	}
}